import { toThousands } from '@/utils/util'
import { getContracts } from '../../api'
import dayjs from 'dayjs'

const column = [
  {
    prop: 'sysChildName',
    label: '孩子姓名'
  },
  {
    prop: 'clienteleName',
    label: '家长姓名'
  },
  {
    prop: 'productName',
    label: '合同产品'
  },
  {
    prop: 'totalAmount',
    label: '合同金额'
  },
  {
    prop: 'statusVal',
    label: '合同状态'
  },
  {
    prop: 'beginDate',
    label: '开始时间'
  },
  {
    prop: 'endDate',
    label: '结束时间'
  },
  {
    prop: 'staffName',
    label: '创建人'
  },
  {
    prop: 'action',
    label: '操作'
  }
]

export const productColum = [
  {
    prop: 'productName',
    label: '产品名称'
  },
  {
    prop: 'practicalAmount',
    label: '实际售价'
  },
  {
    prop: 'count',
    label: '购买数量'
  },
  {
    prop: 'practicalTotalAmount',
    label: '总价'
  },
  {
    prop: 'remark',
    label: '备注'
  }
]

export const contractTypes = {
  'all': {
    title: '全部合同',
    queryFn: getContracts,
    queryPropsParams: {},
    searchItems: () => {
      return [
        {
          key: 'queryKey',
          label: '查询字段',
          type: 'select',
          fieldProps: {
            options: [
              { id: 'name', name: '客户姓名' },
              { id: 'childName', name: '孩子姓名' },
              { id: 'mobile', name: '客户电话' },
              { id: 'monthAge', name: '月龄' }
            ],
            style: {
              width: '136px'
            }
          }
        },
        {
          key: 'queryVal',
          label: '查询内容',
          fieldProps: {
            style: {
              width: '156px'
            }
          }
        },
        {
          key: 'status',
          label: '状态',
          type: 'select',
          fieldProps: {
            options: [
              { id: '0', name: '未开始', type: 'warning' },
              { id: '1', name: '进行中', type: 'primary' },
              { id: '2,3', name: '已结束', type: 'info' }
            ],
            style: {
              width: '126px'
            }
          }
        }
      ]
    },
    column
  },
  'toPayment': {
    title: '待回款合同',
    queryFn: getContracts,
    queryPropsParams: { statusKey: 'wbm' },
    searchItems: () => {
      return [
        {
          key: 'queryKey',
          label: '查询字段',
          type: 'select',
          fieldProps: {
            options: [
              { id: 'name', name: '客户姓名' },
              { id: 'childName', name: '孩子姓名' },
              { id: 'mobile', name: '客户电话' },
              { id: 'monthAge', name: '月龄' }
            ],
            style: {
              width: '136px'
            }
          }
        },
        {
          key: 'queryVal',
          label: '查询内容',
          fieldProps: {
            style: {
              width: '156px'
            }
          }
        }
      ]
    },
    column
  },
  'freeze': {
    title: '已冷冻合同',
    queryFn: getContracts,
    queryPropsParams: { status: '5' },
    searchItems: () => {
      return [
        {
          key: 'queryKey',
          label: '查询字段',
          type: 'select',
          fieldProps: {
            options: [
              { id: 'name', name: '客户姓名' },
              { id: 'childName', name: '孩子姓名' },
              { id: 'mobile', name: '客户电话' },
              { id: 'monthAge', name: '月龄' }
            ],
            style: {
              width: '136px'
            }
          }
        },
        {
          key: 'queryVal',
          label: '查询内容',
          fieldProps: {
            style: {
              width: '156px'
            }
          }
        }
      ]
    },
    column
  }
}

export const infoItems = (info) => {
  console.log(info)
  console.log('fdsfdsfdsfdsf')
  return [
    {
      label: '孩子姓名',
      key: 'sysChildName',
      initialValue: info.sysChildName,
      layoutCol: { sm: 24, md: 24, lg: 24 }
    },
    {
      label: '合同标题',
      key: 'name',
      initialValue: info.name
    },
    {
      label: '合同编号',
      key: 'code',
      initialValue: info.code
    },
    {
      label: '合同金额',
      key: 'totalAmount',
      initialValue: '￥' + info.totalAmount
    },
    {
      label: '签约时间',
      key: 'signDate',
      initialValue: dayjs(info.signDate).format('YYYY/MM/DD HH:mm:ss')
    },
    {
      label: '开始时间',
      key: 'beginDate',
      initialValue: dayjs(info.beginDate).format('YYYY/MM/DD HH:mm:ss')
    },
    {
      label: '结束时间',
      key: 'endDate',
      initialValue: dayjs(info.endDate).format('YYYY/MM/DD HH:mm:ss')
    }
  ]
}

export const infoOtherItems = (info) => {
  return [
    {
      label: '付款阶段',
      key: 'payStatusVal',
      initialValue: info.payStatusVal
    },
    {
      label: '付款方式',
      key: 'payChannelVal',
      initialValue: info.payChannelVal
    },
    {
      label: '已回款金额',
      key: 'practicalAmount',
      initialValue: '￥' + info.practicalAmount
    },
    {
      label: '待回款金额',
      key: 'toBackAmount',
      initialValue: '￥' + toThousands(info.totalAmount - info.practicalAmount)
    },
    {
      label: '可延课天数',
      key: 'surplusLeaveDay',
      initialValue: info.surplusLeaveDay,
      layoutCol: { sm: 24, md: 24, lg: 24 }
    },
    {
      label: '备注',
      key: 'remark',
      initialValue: info.remark,
      layoutCol: { sm: 24, md: 24, lg: 24 }
    },
    {
      label: '附件',
      key: 'attachmentUrl',
      type: 'file',
      initialValue: info.attachmentUrl,
      layoutCol: { sm: 24, md: 24, lg: 24 }
    }
  ]
}

export const stopItems = () => {
  return [
    {
      key: 'breakDownReason',
      label: '终止原因',
      type: 'textarea',
      rules: [{ required: true, message: '请输入终止原因' }]
    },
    {
      key: 'breakDownRemark',
      label: '备注',
      type: 'textarea'
    }
  ]
}
